package com.zuxia.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Bservice;
import com.zuxia.entity.Smalls;
import com.zuxia.service.ISmallsService;

@Controller("smallsAction")
@Scope("prototype")
@ParentPackage("json-default")
@Namespace("/")
@Results({ @Result(name = "findSmallsAll", type = "dispatcher", location = "/admin/smalls.jsp"),
		@Result(name = "json", type = "json"),
		@Result(name = "saveSmalls", type = "redirectAction", location = "/findSmallsAllAdmin"),
		@Result(name = "udpateSmalls", type = "redirectAction", location = "/findSmallsAllAdmin")})
public class SmallsAction extends ActionSupport implements ModelDriven<Smalls> {

	private static final long serialVersionUID = 1L;

	private Smalls smalls = new Smalls();

	public Smalls getModel() {
		return smalls;
	}

	private Map<String, Object> map = new HashMap<String, Object>();
	private String bserviceIds;
	@Resource(name = "smallsService")
	private ISmallsService smallsService;

	@Action("findSmallsAllAdmin")
	public String findSmallsAll() {
		List<Smalls> smallsList = smallsService.findSmallsAll();
		map.put("smallsList", smallsList);
		ActionContext.getContext().getValueStack().push(map);
		return "findSmallsAll";
	}

	@Action("bserviceSmallsFind")
	public String bserviceSmallsFind() {// 锟斤拷询
		List<Bservice> bserviceList = smallsService.bserviceSmallsFind();
		map.put("bserviceList", bserviceList);
		ActionContext.getContext().getValueStack().push(map);
		return "json";
	}

	@Action("saveSmalls")
	public String saveSmalls() {// 锟斤拷锟�
		String resul = smallsService.saveSmalls(smalls);
		return "saveSmalls";
	}

	@Action("findSmallsById")
	public String findSmallsById() {// 锟斤拷锟斤拷锟斤拷询
		Smalls s = smallsService.findSmallsById(smalls);
		map.put("smalls", s);
		ActionContext.getContext().getValueStack().push(map);
		return "json";
	}
	@Action("udpateSmalls")
	public String udpateSmalls() {//锟睫革拷
		return smallsService.udpateSmalls(smalls);
	}
	@Action("deleteSmalls")
	public String deleteSmalls() {//锟斤拷锟斤拷删锟斤拷
		boolean b = smallsService.deleteSmalls(smalls);
		map.put("b", b);
		ActionContext.getContext().getValueStack().push(map);
		return "json";
	}
	@Action("batcheDeleteSmalls")
	public String batcheDeleteSmalls() {
		boolean b = smallsService.batcheDeleteSmalls(bserviceIds);
		map.put("b", b);
		ActionContext.getContext().getValueStack().push(map);
		return "json";
	}
	
	// ----------------------------------getter
	// ------------------------setter------------------------
	public Map<String, Object> getMap() {
		return map;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}

	public String getBserviceIds() {
		return bserviceIds;
	}

	public void setBserviceIds(String bserviceIds) {
		this.bserviceIds = bserviceIds;
	}
}
